/*
 * Copyright (c) 2022 Queclink-C-Library
 *
 * This file is subject to the terms and conditions of the MIT License.
 * For details, please see the LICENSE file or visit the MIT website: https://mit-license.org/
 */

#ifndef QLIBC_STDLIB_H
#define QLIBC_STDLIB_H

#include <stddef.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup stdlib
 * @ingroup common
 * @brief Declare by `#include <qlibc/stdlib.h>`. Some general utility functions.
 * @{
 */

/**
 * @brief   Converts the first few characters of the string pointed to by `nptr` to int.
 * @param[in] nptr The string to convert.
 * @param[in] n    Convert only the first `n` bytes of the string.
 * @return  The converted value or 0 on error.
 * @authors Hubert.Lee, Terry.Huang
 * @date    2022/5/6
 */
int quec_atoi(const char *nptr, size_t n);

/**
 * @brief   Converts the first few characters of the string in `nptr` to a long integer value according to the given `base`, which must be between 2 and 36 inclusive, or be the special value 0.
 * @note    This function is very similar to \b strtol, except that it only converts the first few characters of the string.
 * @param[in] nptr The string to convert.
 * @param[in] n    Convert only the first `n` bytes of the string.
 * @param[in] base Base value. 0 means 16.
 * @return  Same as \b strtol function.
 * @authors Hubert.Lee, Terry.Huang
 * @date    2022/5/6
 */
long int quec_strtol(const char *nptr, size_t n, int base);

/** stdlib
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* QLIBC_STDLIB_H */
